package controllers

import (
	"fmt"
	"myblog/utils"
	"strings"

	beego "github.com/beego/beego/v2/server/web"
)

type ArchivesController struct {
	beego.Controller
}

func (this *ArchivesController) Get() {
	comearchives := this.Ctx.Input.Param(":splat")
	// fmt.Println(comearchives)

	if comearchives == "archives/comearchives" {
		//获取目录
		postdir, _ := beego.AppConfig.String("postdir")
		postdir = utils.GetCurrentPath() + postdir
		if utils.ArchivesFile(postdir) {
			fmt.Println("archives ok")
		}
	}

	archives := strings.SplitN(utils.ReadFile(utils.GetCurrentPath()+"/static/archives/archives"), "\n", -1)
	this.Data["Archives"] = archives
	this.TplName = "model/archives.tpl"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["IndexHead"] = "model/ahead.tpl"
	this.LayoutSections["IndexNavbar"] = "model/navbar.tpl"
	this.LayoutSections["IndexNav"] = "model/nav.tpl"
	this.LayoutSections["IndexFoot"] = "model/afoot.tpl"
	this.Layout = "index.tpl"

}
